<?php

namespace app\http\middleware;

use think\captcha\Captcha;

class CheckCaptcha
{
    public function handle($request, \Closure $next) {

        if ($request->post('captcha') == '') {
            return json(['code' => 1002,'msg'=>lang(1002)]);
        }

        $captcha = new Captcha();
        if (!$captcha->check($request->post('captcha'))) {
            return json(['code' => 1003,'msg'=>lang(1003)]);
        }

        return $next($request);
    }
}
